package mint2tcp;

public class DataParser {
    public static class DataPoint {
        private double latitude;
        private double longitude;
        private double height;
        private double rainfall; // 新增：降雨量 (mm)
        private double cumulativeRainfall; // 新增：累计降雨量 (mm)

        public DataPoint(double latitude, double longitude, double height, double rainfall) {
            this.latitude = latitude;
            this.longitude = longitude;
            this.height = height;
            this.rainfall = rainfall;
            this.cumulativeRainfall = 0; // 初始化累计降雨量
        }

        public double getLatitude() {
            return latitude;
        }

        public double getLongitude() {
            return longitude;
        }

        public double getHeight() {
            return height;
        }

        public double getRainfall() {
            return rainfall;
        }

        public double getCumulativeRainfall() {
            return cumulativeRainfall;
        }

        public void addRainfall(double rainfall) {
            this.rainfall = rainfall;
            this.cumulativeRainfall += rainfall; // 累加降雨量
        }
    }

    public static DataPoint parseData(String data) {
        // 假设数据格式为 "LAT,LON,HEIGHT,PULSES"
        // 例如: "39.9042,116.4074,100,10" (10 个脉冲)
        String[] parts = data.split(",");
        if (parts.length < 4) {
            return new DataPoint(0, 0, 0, 0);
        }

        double latitude = Double.parseDouble(parts[0]);
        double longitude = Double.parseDouble(parts[1]);
        double height = Double.parseDouble(parts[2]);
        double pulses = Double.parseDouble(parts[3]); // 脉冲数

        // 计算降雨量，假设每脉冲 0.1mm
        double rainfall = pulses * 0.1;

        return new DataPoint(latitude, longitude, height, rainfall);
    }
}